home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 147 / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin / docs / ippon / ver / 011 / ippon011.lzh / player.c < prev    next >
C/C++ Source or Header  |  2000-07-07  |  3KB  |  125 lines

  1. /* player.c */
  2.  
  3. #include <sys/iocs.h>
  4. #include <xsp2lib.h>
  5.  
  6. #include "main.h"
  7. #include "player.h"
  8. #include "shot.h"
  9.  
  10. #define PLAYER_BANK1    8    /* 少し傾きパターンへ移行するまでの値 */
  11. #define PLAYER_BANK2    12    /* 一番傾きパターンへ以下同文 */
  12.  
  13. #define PLAYER_SPEED    15    /* 自機の速度 */
  14.  
  15.  
  16. enum {
  17.     PLAYER_PT_RIGHT2 = 0,    /* 自機が一番右に傾いている時のパターン */
  18.     PLAYER_PT_RIGHT1,    /*  〃 少し右に     〃      */
  19.     PLAYER_PT_CENTER,    /*  〃 正面を向いている時のパターン */
  20.     PLAYER_PT_LEFT1,    /* 自機が少し右に傾いている時のパターン */
  21.     PLAYER_PT_LEFT2        /*  〃 一番右に     〃      */
  22. };
  23.  
  24.  
  25.  
  26. /* ゲーム開始時に呼ばれる */
  27. void PlayerInit (void)
  28. {
  29. }
  30.  
  31.  
  32.  
  33. /* プレイヤー出現時に呼ばれる */
  34. void PlayerAlloc (void)
  35. {
  36.     player->lx = 144 * 65536;
  37.     player->ly = 144 * 65536;
  38.     player->bank = 0;
  39. }
  40.  
  41.  
  42.  
  43. /* 垂直同期ごとに呼ばれる */
  44. void PlayerMove (void)
  45. {
  46.     int j;            /* ジョイスティックの入力 */
  47.  
  48.     j = _iocs_joyget (0);    /* ジョイスティック0番 */
  49.  
  50.     /* [A] ボタンが押されたか? */
  51.     if ((j & 0b00100000) == 0)
  52.         game_over = !0;    /* ゲームオーバーに */
  53.  
  54.     /* [B] ボタンが押されたか? */
  55.     if ((j & 0b1000000) == 0)
  56.         ShotAlloc();
  57.  
  58.     /* 自機の上下移動処理 */
  59.     switch (j & 0b0011) {
  60.     case 0b0010:        /* 上 */
  61.         player->ly += xytable[PLAYER_SPEED][192].y;
  62.         break;
  63.     case 0b0001:        /* 下 */
  64.         player->ly += xytable[PLAYER_SPEED][64].y;
  65.         break;
  66.     default:        /* それ以外 */
  67.         break;
  68.     }
  69.  
  70.     /* 自機の左右移動処理+左右傾き処理 */
  71.     switch (j & 0b1100) {
  72.     case 0b1000:        /* 左 */
  73.         player->lx += xytable[PLAYER_SPEED][128].x;
  74.         if (player->bank > 0) {
  75.             player->bank = 0;
  76.         } else {
  77.             if (player->bank > -PLAYER_BANK2)
  78.                 player->bank--;
  79.         }
  80.         break;
  81.  
  82.     case 0b0100:        /* 右 */
  83.         player->lx += xytable[PLAYER_SPEED][0].x;
  84.         if (player->bank < 0) {
  85.             player->bank = 0;
  86.         } else {
  87.             if (player->bank < PLAYER_BANK2)
  88.                 player->bank++;
  89.         }
  90.         break;
  91.  
  92.     default:        /* それ以外 */
  93.         /* 自機の傾きを元に戻す処理 */
  94.         if (player->bank != 0) {
  95.             if (player->bank > 0)
  96.                 player->bank--;
  97.             else
  98.                 player->bank++;
  99.         }
  100.         break;
  101.     }
  102.  
  103.     /* 自機の傾き (player->bank) から自機の複合スプライトNo.を求める */
  104.     if (player->bank == 0) {
  105.         player->pt = obj_player + PLAYER_PT_CENTER;
  106.     } else {
  107.         if (player->bank > 0) {
  108.             if (player->bank < PLAYER_BANK1)
  109.                 player->pt = obj_player + PLAYER_PT_LEFT1;
  110.             else
  111.                 player->pt = obj_player + PLAYER_PT_LEFT2;
  112.         } else {
  113.             if (player->bank > -PLAYER_BANK1)
  114.                 player->pt = obj_player + PLAYER_PT_RIGHT1;
  115.             else
  116.                 player->pt = obj_player + PLAYER_PT_RIGHT2;
  117.         }
  118.     }
  119.  
  120.     player->x = player->lx / 65536;
  121.     player->y = player->ly / 65536;
  122.  
  123.     xobj_set (player->x, player->y, player->pt, 0x073f);    /* 自機を表示 */
  124. }
  125.